#ifndef GRAPHICS_RENDERABLE_H
#define GRAPHICS_RENDERABLE_H

//STL includes
#include <list>

//Graphics
#include "../Math/Point.h"
#include "../Math/Quaternion.h"
#include "Texture.h"

//OpenGL Utility Library
#include "GLUT.h"

using namespace Math;

namespace Graphics
{
	class Renderable
	{
		public:
				typedef std::list<Renderable*> ListT;

				/** Default constructor. Builds a Renderable with a specified optional parent. Dynamic Renderables are always redrawn and do not have display list ids. */
				Renderable(Renderable* p=NULL, bool d=false);

				/**********
				* GETTERS *
				**********/
				/** [read-only] Returns the unique display id of the the Renderable object.*/
				GLuint id() const;
				/** */
				Texture* texture() const;
				/** [read-write] Returns the parent Renderable, if any. Otherwise returns NULL. */
				Renderable* parent() const;
				bool willRedraw() const;
				Point* position();
				Quaternion* rotation();

				/**********
				* SETTERS *
				**********/
				void setTexture(Texture* tex);
				void setParent(Renderable* d);
				void setDynamic(bool dynamic);
				void setRedraw(bool redraw);
				void setPosition(const Point& pos);
				void setRotation(const Quaternion& rot);

				//Rotation
				void rotateX(float amount);
				void rotateY(float amount);
				void rotateZ(float amount);

				//Translation
				void move(const Point& pos);
				void move(const Vector& amount);

				/*************
				* COLLECTION *
				*************/
				/** Adds a Renderable child to this Renderable object */
				void add(Renderable* d);
				/** Removes a child Renderable */
				void remove(Renderable* d);
				int count();
				ListT* children();

				/**********
				* DRAWING *
				**********/
				/** Lets subclasses specify the geometry, textures, etc */
				virtual void redraw() { _redraw=false;};

				/** Main drawing routine. Calls redraw() if necessary */
				virtual void draw();

		protected:
				GLuint _id;
				Texture* _texture;
				Renderable* _parent;
				Point _position;
				Quaternion _rotation;

				ListT _children;

				bool _redraw;
				bool _dynamic;

				/** Renders the Renderable and all its children on the screen */
				void render();

				void createID();
	};
}
#endif
